package com.kmxd.ams.controller.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.kmxd.ams.client.system.ISysUserConfigSvc;
import com.kmxd.ams.client.system.dto.SysUserConfigAddDTO;
import com.kmxd.ams.client.system.dto.SysUserConfigQueryDTO;
import com.kmxd.ams.client.system.vo.SysUserConfigListVO;
import com.kmxd.ams.core.common.enums.LogLevelEnum;
import com.kmxd.ams.core.common.enums.LogTypeEnum;
import com.kmxd.ams.core.log.annotation.AutoLog;
import com.kmxd.ams.core.result.R;
import com.kmxd.ams.core.util.SecurityUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 用户配置表 前端控制器
 *
 * @author nickbi
 * @since 2022-07-16
 */
@RestController
@Tag(name = "用户配置表")
@RequestMapping("/system/sysUserConfig")
@AllArgsConstructor
public class SysUserConfigCtl {

  private ISysUserConfigSvc sysUserConfigService;

  /** 新增 */
  @Operation(summary = "修改配置")
  @PostMapping("/change")
  @SaCheckPermission("system:sysUserConfig:change")
  @AutoLog(module = "用户配置表", type = LogTypeEnum.SYSTEM, level = LogLevelEnum.HIGH, title = "修改")
  public R<Void> add(@Validated @RequestBody SysUserConfigAddDTO req) {
    req.setUserId(SecurityUtil.getUserId());
    sysUserConfigService.change(req);
    return R.success();
  }

  /** 查看 */
  @Operation(summary = "当前用户的配置")
  @GetMapping("/current")
  @SaCheckPermission("system:sysUserConfig:current")
  @AutoLog(module = "用户配置表", type = LogTypeEnum.SYSTEM, level = LogLevelEnum.MEDIUM, title = "查看")
  public R<List<SysUserConfigListVO>> current() {
    SysUserConfigQueryDTO dto = new SysUserConfigQueryDTO();
    dto.setUserId(SecurityUtil.getUserId());
    return R.success(sysUserConfigService.selectList(dto));
  }
}
